package com.qc.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qc.common.Session;
import com.qc.entity.BusinessFollow;
import com.qc.entity.InterestUserEntity;
import com.qc.service.BusinessFollowService;
import com.qc.service.InterestUserService;

import net.sf.json.JSONObject;

@Controller
public class InterestUserController extends BaseController{
	
	@Resource(name="interestUserService")
	private InterestUserService interestUserService;
	
	@Resource(name="businessFollowService")
	private BusinessFollowService businessFollowService;

	/**
	 * 我的  最近来访
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/MobileInterestUserGetAllAccess", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String MobileInterestUserGetAllAccess(HttpServletRequest request, HttpServletResponse response) {

		String p1 = request.getParameter("p1");
		String p2 = request.getParameter("p2");
		long userId = Session.getUserIdfromMobileSession(p2);
		
		InterestUserEntity interestUserEntity = (InterestUserEntity)JSONObject.toBean(JSONObject.fromObject(p1), InterestUserEntity.class);
		List<InterestUserEntity> list = null;
		//  1 我的粉丝  2我的关注
		if (1 == interestUserEntity.getType()) {
			
			list = interestUserService.listAllInterestUser(0, userId, interestUserEntity.getPageNo(),interestUserEntity.getPageSize());
		}else {
			list = interestUserService.listAllInterestUser(userId, 0, interestUserEntity.getPageNo(),interestUserEntity.getPageSize());
		}
		
		for (InterestUserEntity entity : list) {
			
			entity.setModifiedTime(entity.getModifiedTime().substring(0,19));
		}
		return returnSuccessResult(list);
	}
	
	/**
	 * 我的 我关注的商家
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/MobileBusinessFollowGetAllAccess", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String MobileBusinessFollowGetAllAccess(HttpServletRequest request, HttpServletResponse response) {

		String p1 = request.getParameter("p1");
		String p2 = request.getParameter("p2");
		long userId = Session.getUserIdfromMobileSession(p2);
		
		BusinessFollow businessFollow = (BusinessFollow)JSONObject.toBean(JSONObject.fromObject(p1), BusinessFollow.class);
		
		List<BusinessFollow> list = businessFollowService.listAllBusinessFollow(userId, businessFollow.getPageNo(), businessFollow.getPageSize());
		
		return returnSuccessResult(list);
	}
	
	
}
